﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace NCRGEA.UserControls
{
    public partial class ucLogs : UserControl
    {
        private int _MemberID;
        public int MemberID
        {
            get
            {
                return _MemberID;
            }
            set
            {
                _MemberID = value;
                this.RefreshData();
            }
        }
        public ucLogs()
        {
            InitializeComponent();
        }

        public ucLogs(int MemberID) : this()
        {
            this.MemberID = MemberID;
            RefreshData();
        }

        private void RefreshData()
        {
            string sqlQry = @"SELECT
	                            ua.Username,
                                ln.Date,
                                ln.Description
                            FROM
	                            logActions ln
	                            LEFT JOIN
		                            usrAccounts ua
	                            ON
		                            ln.StaffID=ua.StaffID
                            WHERE
	                            ln.MemberID=@MemberID
                            ORDER BY
                                ln.Date DESC";
            SqlParameter[] sParamArray = new SqlParameter[1];
            sParamArray[0] = new SqlParameter("@MemberID", _MemberID) { SqlDbType = SqlDbType.Int };
            DataTable logs = AAL.DAL.ExecuteQuery(sqlQry, sParamArray);
            if (logs != null)
                grdLog.DataSource = logs;
        }
    }
}
